*     *****************************************************************    *;
*     *****************************************************************    *;
*   Date:        June 2021   		                                       *;
*   Authors:     Dellmuth, Scholte, Tallberg, and Verhaegen                *;
*   Purpose:     Recode dyadic dataset made in step 1     				   *;
*     *****************************************************************    *;
*     *****************************************************************    *;

set more off     
vers 16.1

***************************
*create DIFF variables
***************************

*note: "_d" denotes variables for citizens


use dyads.dta, clear

drop resptype 

gen DIFFlr =leftright-leftright_d
gen DIFFfinsathh= finsathousehold-finsathousehold_d

tab confUN
replace confUN =3 if confUN==4
replace confIMF =3 if confUN==4
replace confICC =3 if confUN==4
replace confWB =3 if confUN==4
replace confWHO =3 if confUN==4
replace confWTO =3 if confUN==4
tab confUN_d
recode confUN_d 4=3 3=2 2=1 1=0
recode confIMF_d 4=3 3=2 2=1 1=0
recode confICC_d 4=3 3=2 2=1 1=0
recode confWB_d 4=3 3=2 2=1 1=0
recode confWHO_d 4=3 3=2 2=1 1=0
recode confWTO_d 4=3 3=2 2=1 1=0
drop confios confios_d
gen confios= (confUN +confIMF +confICC +confWB +confWHO +confWTO)/6
gen confios_d= (confUN_d +confIMF_d +confICC_d +confWB_d +confWHO_d +confWTO_d)/6

gen DIFFconfios=confios-confios_d
gen DIFFconfICC=confICC-confICC_d
gen DIFFconfUN=confUN-confUN_d
gen DIFFconfWHO=confWHO-confWHO_d
gen DIFFconfIMF=confIMF-confIMF_d
gen DIFFconfWB=confWB-confWB_d
gen DIFFconfWTO=confWTO-confWTO_d

tab edu_d
gen DIFFedu= edu-edu_d
sum DIFFedu

tab feelworld 
tab feelworld_d 
gen DIFFfeelworld=feelworld-feelworld_d
gen DIFFfeelcountry= feelcountry-feelcountry_d

tab confgov
tab confgov_d
gen DIFFconfgov = confgov-confgov_d

tab satis
tab satis_d
gen DIFFsatis = satis-satis_d
sum DIFFsatis

tab ethliberal
*gen TAN_GAL = (((((homo+divorce+sexmarriage+abort)/8)+immigrants)/2)/5 + comb_ordernation)/2
*gen GAL = ((ethliberal/9)+(immigrants/4)+(xcomb_NOTordernation/2))/3
sum TAN_GAL TAN_GAL_d
mean TAN_GAL 
* mean == 1.796285 
mean TAN_GAL_d
* mean ==  1.45714 
*dummy based on the mean
drop gal
gen gal=.
replace gal=0 if TAN_GAL < 1.796285 
replace gal=1 if TAN_GAL >= 1.796285  
gen gal_d=.
replace gal_d=0 if TAN_GAL_d <  1.45714 
replace gal_d=1 if TAN_GAL_d >=  1.45714 
gen DIFFgal=gal-gal_d // -1 if elites more gal, 0 if no diff (baseline: 1 if citizens more gal)
tab DIFFgal
*gen DIFFTAN_GAL = TAN_GAL_d-TAN_GAL 
*corr DIFFgal DIFFTAN_GAL
*hist DIFFTAN_GAL
recode DIFFgal -1=1 1=2
label define gal 0 "No difference" 1 "Elites TAN and citizen GAL" 2 "Citizen TAN and elite GAL", modify
label values DIFFgal gal
tab DIFFgal

tab trust_d
tab country, nol 
by country, sort:tab trust  
replace trust=0 if trust==2 & country==608 // 0 = tend not to trust
gen DIFFtrust = trust -trust_d
tab DIFFtrust // 1 if elites more trust, 0 if no diff (baseline: - 1 if ciitizens more trust) 
recode DIFFtrust -1=1 1=2
label define trust 0 "No difference" 1 "Citizens more social trust" 2 "Elites more social trust", modify
label values DIFFtrust trust
tab DIFFtrust


gen DIFFage = age-age_d
tab sex //1=male, 2=female 
tab sex_d
recode sex 3=.
gen DIFFsex = sex -sex_d
tab DIFFsex // 1 if citizen woman and elite man, 0 if no diff (baseline: -1 if elite woman and citizen man)
recode DIFFsex -1=2
label define sex 0 "No difference" 1 "Elite woman and citizen man" 2 "Elite man and citizen woman", modify
label values DIFFsex sex

summarize DIFFedu DIFFgal DIFFfeelworld DIFFfeelcountry DIFFconfgov DIFFsatis DIFFtrust  DIFFage  DIFFsex


compress

save dyads_recoded.dta, replace







